package com.example.demo.service;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author gyc
 * @date 2018/1/5
 */
@Service
public class UserServiceImpl implements UserService {
    @Resource
    private JdbcTemplate jdbcTemplate;


    @Override
    public void create(Integer id, String username, Integer password, String nickname, Integer status) {
        jdbcTemplate.update("insert into USER(id,username,password,nickname,status) values(?,?,?,?,?)", id,username,password,nickname,status);
    }

    @Override
    public void deleteByName(String username) {
        jdbcTemplate.update("DELETE FROM USER WHERE username=?",username);
    }

    @Override
    public Integer getAllUsers() throws Exception{
        Integer total=jdbcTemplate.queryForObject("SELECT COUNT(1) FROM USER",Integer.class);
        return total;
    }

    @Override
    public void deleteAllUsers() {
        jdbcTemplate.update("DELETE FROM USER ");
    }
}
